package com.estronger.shopmanage.ui.grab.presenter;

import com.estronger.shopmanage.ui.grab.activity.GrabPondActivity;
import com.estronger.shopmanage.ui.grab.bean.GrabOrderBean;
import com.google.gson.Gson;
import com.soonfor.evaluate.base.IEvalBasePresenter;
import com.soonfor.evaluate.http.api.Request;
import com.soonfor.evaluate.http.httptools.AsyncUtils;

import org.json.JSONObject;

/**
 * Created by Administrator on 2018-01-29.
 */

public class GrabBasePresenter implements IEvalBasePresenter, AsyncUtils.AsyncCallback {

    private GrabPondActivity gpActivity;

    public void getData(int pageNo, boolean isNeedShowLoadDialog) {
        if (isNeedShowLoadDialog) {
            this.gpActivity.showLoadingDialog();
        }
        //获取待抢任务列表
        Request.Grab.getGraborderList(gpActivity, pageNo, this);//取所有待抢任务
    }

    public GrabBasePresenter(GrabPondActivity gpActivity) {
        this.gpActivity = gpActivity;
    }

    @Override
    public void success(int requestCode, String data) {
        Gson gson = new Gson();
        switch (requestCode) {
            case Request.Grab.GET_GRABORDER_TASK_LIST:
                try {
                    JSONObject jo = new JSONObject(data);
                    GrabOrderBean orderBean = gson.fromJson(data, GrabOrderBean.class);
                    if(orderBean!=null) gpActivity.setListView(true, orderBean, null);
                    else gpActivity.setListView(false, null, "数据为空");
                } catch (Exception e) {
                    gpActivity.showNoDataHint("请求出错");
                }
                gpActivity.closeLoadingDialog();
                break;

        }
    }

    @Override
    public void fail(int requestCode, int statusCode, String data, String msg) {
        gpActivity.closeLoadingDialog();
        gpActivity.showNoDataHint(msg);
    }

}
